﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VatTuDTO;
using VatTuBUS1;

namespace CungUngXayDung.admin
{
    public partial class QLSanPham : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadDanhsachSP();
        }


        void LoadDanhsachSP()
        {
            List<SanPhamDTO> list = new List<SanPhamDTO>();
            list = new SanPhamBUS().SelectSanPham();

            GridView1.DataSource = list;

            GridView1.DataBind();
            Dispose();
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            LoadDanhsachSP();
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int row = int.Parse(GridView1.Rows[Convert.ToInt32(e.RowIndex)].Cells[0].Text.ToString());
            new SanPhamBUS().DeleteSanPham(row);
            LoadDanhsachSP();
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            int row = int.Parse(GridView1.Rows[e.NewEditIndex].Cells[0].Text.ToString());
            string url = "ChiTietSanPham.aspx?catid=" + row;
            Response.Redirect(url);
        }

     

        protected void btnThem_Click(object sender, EventArgs e)
        {
            string url = "ChiTietSanPham.aspx?catid=0";
            Response.Redirect(url);
        }

    }
}